﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

/*
 * 说明：暂未启用
 * 需要命名空间: using System.Data.OleDb;
 * 需要组件:     Microsoft.Vbe.Interop.dll 
 */

namespace Vincent._Excel
{
    /// <summary>
    /// Excel数据导入
    /// </summary>
    public class InputExcel
    {
        /// <summary> 
        /// 读取Excel文档中的数据到内存中 
        /// </summary> 
        /// <param name="Path"> 文件名称 </param> 
        /// <returns> 返回一个数据集 </returns> 
        //public static DataSet ExcelToDataSet(string Path)
        //{
        //    DataSet ds = new DataSet();

        //    string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";

        //    OleDbConnection conn = new OleDbConnection(strConn);
        //    conn.Open();
        //    string strExcel = "";
        //    OleDbDataAdapter myCommand = null;

        //    strExcel = "select * from [Sheet1$]";
        //    myCommand = new OleDbDataAdapter(strExcel, strConn);
        //    myCommand.Fill(ds);

        //    return ds;
        //}

        ///// <summary>
        ///// 将DataSet中的数据插入到SqlServer中
        ///// </summary>
        ///// <param name="ds"> 结果集 </param>
        ///// <param name="TableName"> 表名 </param>
        ///// <param name="MasterID"> 订单主表ID </param>
        //public static void DataSetToSqlServer(DataSet ds, string TableName, string MasterID)
        //{
        //    DataTable dt = new DataTable();
        //    long ID = Shove._Convert.StrToLong(MasterID, 0);     //主表ID

        //    if (ds != null && ds.Tables.Count > 0)
        //    {
        //        dt = ds.Tables[0];

        //        for (int i = 0; i < dt.Rows.Count; i++)
        //        {
        //            string GoodNo = dt.Rows[i][0].ToString();
        //            string GoodNorm = dt.Rows[i][1].ToString();
        //            int Amount = Shove._Convert.StrToInt(dt.Rows[i][2].ToString(), 0);

        //            DAL.Procedures.P_DataTableToSqlServer(TableName, ID, GoodNo, GoodNorm, Amount);
        //        }
        //    }
        //}
    }
}
